﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DataTransferObject;
using BusinnessLogicLayer;
using DevExpress.XtraEditors.Controls;

namespace PresentationLayer
{
    public partial class ucStanding : DevExpress.XtraEditors.XtraUserControl
    {
        DTOSeason _dtoSeason = new DTOSeason();
        BUSSeason _busSeason = new BUSSeason();
        string seasonName = "";
        string seasonID = "";
        DataTable dtSeason;
        DataTable dtStanding;

        public ucStanding()
        {
            InitializeComponent();
            // This line of code is generated by Data Source Configuration Wizard
            standingTableAdapter1.Fill(sangldDataSet1.STANDING);
            //Load thong tin season vao cbx
            LoadSeason();
            //Load thong tin Bang xep hang theo season
            LoadStanding(seasonName);
        }

        public void LoadSeason()
        {
            ComboBoxItemCollection coll = cbxSeason.Properties.Items;
            coll.BeginUpdate();
            dtSeason = _busSeason.getAllData();
            for (int i = 0; i < dtSeason.Rows.Count; i++)
            {
                coll.Add((dtSeason.Rows[i]["SeasonName"]).ToString());
                if (i == dtSeason.Rows.Count - 1)
                {
                    seasonID = (dtSeason.Rows[i]["SeasonID"]).ToString();
                }
            }
            coll.EndUpdate();

            cbxSeason.SelectedIndex = coll.Count - 1;
            seasonName = cbxSeason.SelectedItem.ToString();
            labelSeason.Text = " " + seasonName;
        }

        public void LoadStanding(string seasonName)
        {
            //load thong tin bang xep hang o day theo mua giai
        }

        private void sTANDINGBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.sTANDINGBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.sangldDataSet);

        }

        private void cbxSeason_SelectedIndexChanged(object sender, EventArgs e)
        {
            //thay doi standing o day

            for (int i = 0; i < dtSeason.Rows.Count; i++)
            {
                if ((dtSeason.Rows[i]["SeasonName"]).Equals(cbxSeason.SelectedItem.ToString()))
                {
                    seasonID = (dtSeason.Rows[i]["SeasonID"]).ToString();
                }
            }
            seasonName = cbxSeason.SelectedItem.ToString();
            labelSeason.Text = " " + seasonName;
        }
    }
}
